package com.coffee.daili.service.impl;

import java.math.BigDecimal;
import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.coffee.admin.api.merchant.query.MerchantQuery;
import com.coffee.admin.api.supplier.query.SupplierQuery;
import com.coffee.admin.service.common.bean.GtRegion;
import com.coffee.admin.service.common.dao.GtRegionDao;
import com.coffee.admin.service.merchant.bean.Merchant;
import com.coffee.admin.service.merchant.dao.MerchantDao;
import com.coffee.admin.service.platform.bean.Platform;
import com.coffee.admin.service.platform.dao.PlatformDao;
import com.coffee.admin.service.supplier.bean.Supplier;
import com.coffee.admin.service.supplier.dao.SupplierDao;
import com.coffee.core.entity.Page;
import com.coffee.core.entity.PagerInfo;
import com.coffee.core.enums.DailiMerchantRoleEnum;
import com.coffee.core.enums.DailiMerchantStatusEnum;
import com.coffee.core.enums.ExceptionEnum;
import com.coffee.core.enums.IntegralOperationEnum;
import com.coffee.core.exception.BusinessException;
import com.coffee.core.exception.ValidateBusinessException;
import com.coffee.core.util.BeanUtilExt;
import com.coffee.core.util.DTOUtils;
import com.coffee.core.util.StringUtil;
import com.coffee.daili.api.query.DailiMerchantQuery;
import com.coffee.daili.api.query.DailiMerchantSkuQuery;
import com.coffee.daili.api.query.DailiOrderQuery;
import com.coffee.daili.api.req.InsertMerchantReq;
import com.coffee.daili.api.result.DailiMerchantResult;
import com.coffee.daili.api.result.DailiSupplierSubOrderResult;
import com.coffee.daili.api.service.DailiMerchantService;
import com.coffee.daili.service.bean.DailiMerchant;
import com.coffee.daili.service.bean.DailiMerchantQuotaLog;
import com.coffee.daili.service.bean.DailiMerchantSku;
import com.coffee.daili.service.dao.*;
import com.coffee.order.service.sku.dao.SkuOrderDao;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.*;


@DubboService(dynamic = true)
public class DailiMerchantServiceImpl implements DailiMerchantService {
    private static final Logger LOG = LoggerFactory.getLogger(DailiMerchantServiceImpl.class);
    @Resource
    private DailiMerchantDao dailiMerchantDao;
    @Resource
    private SupplierDao supplierDao;
    @Resource
    private PlatformDao platformDao;
    @Resource
    private MerchantDao merchantDao;
    @Resource
    private GtRegionDao gtRegionDao;
    @Resource
    private DailiMerchantSkuDao dailiMerchantSkuDao;
    @Resource
    private DailiMerchantQuotaLogDao dailiMerchantQuotaLogDao;
    @Resource
    private DailiOrderDao dailiOrderDao;
    @Resource
    private SkuOrderDao skuOrderDao;

    @Override
    public Page<DailiMerchantResult> getPager(DailiMerchantQuery param, PagerInfo pr) {
        Page<DailiMerchantResult> pager = new Page<DailiMerchantResult>(pr.getStart(), pr.getPageSize());
        Integer count = dailiMerchantDao.count(param);
        pager.setTotalPage(count);
        if (count > 0) {
            List<DailiMerchant> list = dailiMerchantDao.page(param, pr.getStart(), pr.getPageSize());
            List<DailiMerchantResult> DailiMerchantResults = DTOUtils.convertList(list, DailiMerchantResult.class);
            for (DailiMerchantResult dailiMerchantResult : DailiMerchantResults) {
                SupplierQuery supplierQuery = new SupplierQuery();
                supplierQuery.setMobile(dailiMerchantResult.getMobile());
                supplierQuery.setPid(0);
                Supplier supplier = supplierDao.findFirst(supplierQuery);
                if (supplier != null) {
                    dailiMerchantResult.setBusinessName(supplier.getBusinessName());
                    dailiMerchantResult.setBusinessCode(supplier.getBusinessCode());
                    dailiMerchantResult.setName(supplier.getName());
                }
                if (dailiMerchantResult.getProvinceId() != null) {
                    GtRegion province = gtRegionDao.findById(dailiMerchantResult.getProvinceId());
                    if (province != null)
                        dailiMerchantResult.setProvinceName(province.getName());
                }
                if (dailiMerchantResult.getCityId() != null) {
                    GtRegion city = gtRegionDao.findById(dailiMerchantResult.getCityId());
                    if (city != null)
                        dailiMerchantResult.setCityName(city.getName());
                }
                if (dailiMerchantResult.getAreaId() != null) {
                    GtRegion area = gtRegionDao.findById(dailiMerchantResult.getAreaId());
                    if (area != null)
                        dailiMerchantResult.setAreaName(area.getName());
                }
                LOG.info("dailiMerchantResult===" + JSONObject.toJSONString(dailiMerchantResult));
                Map<String, Object> stringObjectMap = dailiOrderDao.countByDailiMerchantPidPath(param.getStartTime(), param.getEndTime(), dailiMerchantResult.getPidPath());
                Integer dailiOrderListCount = dailiOrderDao.getDailiOrderListCount(null, param.getStartTime(), param.getEndTime(), dailiMerchantResult.getPidPath());
                LOG.info("stringObjectMap===" + JSONObject.toJSONString(stringObjectMap));
                LOG.info("dailiOrderListCount===" + dailiOrderListCount);
                dailiMerchantResult.setOrderCount(dailiOrderListCount);
                dailiMerchantResult.setTotalAmount(new BigDecimal(stringObjectMap.get("payAmount") + "").doubleValue());
            }
            pager.setData(DailiMerchantResults);
        }
        return pager;
    }

    @Override
    public Integer count(DailiMerchantQuery param) {
        Integer count = dailiMerchantDao.count(param);
        return count;
    }

    @Override
    public DailiMerchantResult getDetail(Integer id) {
        DailiMerchant item = dailiMerchantDao.findById(id);
        if (item == null) {
            return null;
        }
        DailiMerchantResult result = new DailiMerchantResult();
        BeanUtilExt.copyProperties(result, item);
        SupplierQuery supplierQuery = new SupplierQuery();
        supplierQuery.setMobile(result.getMobile());
        supplierQuery.setPid(0);
        Supplier supplier = supplierDao.findFirst(supplierQuery);
        if (supplier != null) {
            result.setBusinessName(supplier.getBusinessName());
            result.setBusinessCode(supplier.getBusinessCode());
            result.setName(supplier.getName());
        }
        if (result.getProvinceId() != null) {
            GtRegion province = gtRegionDao.findById(result.getProvinceId());
            if (province != null)
                result.setProvinceName(province.getName());
        }
        if (result.getCityId() != null) {
            GtRegion city = gtRegionDao.findById(result.getCityId());
            if (city != null)
                result.setCityName(city.getName());
        }
        if (result.getAreaId() != null) {
            GtRegion area = gtRegionDao.findById(result.getAreaId());
            if (area != null)
                result.setAreaName(area.getName());
        }
        DailiMerchantSkuQuery param = new DailiMerchantSkuQuery();
        param.setDailiMerchantId(item.getId());
        Integer count = dailiMerchantSkuDao.count(param);
        result.setSkuCount(count);
        List<Integer> skuIds = dailiMerchantSkuDao.findIds(id);
        result.setSkuIds(skuIds);
        return result;
    }

    @Override
    public List<DailiMerchantResult> getList(DailiMerchantQuery param, PagerInfo pr) {
        List<DailiMerchant> list = dailiMerchantDao.page(param, pr.getStart(), pr.getPageSize());
        return DTOUtils.convertList(list, DailiMerchantResult.class);
    }

    @Override
    public List<DailiMerchantResult> getList(DailiMerchantQuery param) {
        List<DailiMerchant> list = dailiMerchantDao.page(param, 0, Integer.MAX_VALUE);
        return DTOUtils.convertList(list, DailiMerchantResult.class);
    }

    @Override
    public List<DailiMerchantResult> getList() {
        DailiMerchantQuery param = new DailiMerchantQuery();
        List<DailiMerchant> list = dailiMerchantDao.page(param, 0, Integer.MAX_VALUE);
        return DTOUtils.convertList(list, DailiMerchantResult.class);
    }


    @Override
    public void delete(Integer id) {
        dailiMerchantDao.deleteById(id);
    }

    @Override
    public void update(DailiMerchantResult result) throws BusinessException {
        DailiMerchant item = new DailiMerchant();
        BeanUtilExt.copyProperties(item, result);
        DailiMerchant tmp = dailiMerchantDao.findById(item.getId());
        if (tmp == null) {
            throw new BusinessException(ExceptionEnum.ERROR_0002.getCode(), ExceptionEnum.ERROR_0002.getMessage());
        }
        if (item.getProvinceId() != null || item.getCityId() != null || item.getAreaId() != null
                || StringUtils.isNotEmpty(item.getIsEnable()) || item.getPeopleNumber() != null
                || item.getQuota() != null) {
            dailiMerchantDao.updateById(item);
        }
        List<Integer> updateSkuIds = result.getSkuIds();
        if (updateSkuIds != null && updateSkuIds.size() > 0) {
            List<Integer> skuIds = dailiMerchantSkuDao.findIds(result.getId());
            //删除
            Collection subtract = CollectionUtils.subtract(skuIds, updateSkuIds);
            List<Integer> deleteList = new ArrayList<>(subtract);
            if (deleteList.size() > 0) {
                dailiMerchantSkuDao.deleteBySkuIds(item.getId(), deleteList);
            }

            //
            Collection addSubtract = CollectionUtils.subtract(updateSkuIds, skuIds);
            List<Integer> addList = new ArrayList<>(addSubtract);
            List<DailiMerchantSku> addDailiMerchantSkuIdList = new ArrayList<>();
            if (addList.size() > 0) {
                for (Integer skuId : addList) {
                    DailiMerchantSku dailiMerchantSku = new DailiMerchantSku();
                    dailiMerchantSku.setDailiMerchantId(item.getId());
                    dailiMerchantSku.setDailiSkuId(skuId);
                    dailiMerchantSku.setCreateTime(new Date());
                    addDailiMerchantSkuIdList.add(dailiMerchantSku);
                }
                dailiMerchantSkuDao.insertBatch(addDailiMerchantSkuIdList);
            }
        }
        if (result.getQuota() != null && !result.getQuota().equals(tmp.getQuota())) {
            Platform platform = platformDao.findById(result.getPlatformId());
            DailiMerchantQuotaLog dailiMerchantQuotaLog = new DailiMerchantQuotaLog();
            dailiMerchantQuotaLog.setDailiMerchantId(item.getId());
            dailiMerchantQuotaLog.setQuota(result.getQuota());
            dailiMerchantQuotaLog.setName(platform.getName());
            dailiMerchantQuotaLog.setCreateTime(new Date());
            dailiMerchantQuotaLogDao.insert(dailiMerchantQuotaLog);
        }
    }

    @Override
    public void updateByMerchant(DailiMerchantResult result) throws BusinessException {
        DailiMerchant tmp = dailiMerchantDao.findById(result.getId());
        if (tmp == null) {
            throw new BusinessException(ExceptionEnum.ERROR_0002.getCode(), ExceptionEnum.ERROR_0002.getMessage());
        }
        Merchant merchant = merchantDao.findById(result.getMerchantId());
        DailiMerchantQuery daliMerchantQuery = new DailiMerchantQuery();
        daliMerchantQuery.setMobile(merchant.getMobile());
        DailiMerchant daliMerchant = dailiMerchantDao.findFirst(daliMerchantQuery);
        LOG.info("daliMerchant====" + JSONObject.toJSONString(daliMerchant));
        if (daliMerchant == null) {
            throw new BusinessException(ExceptionEnum.ERROR_1902.getCode(), ExceptionEnum.ERROR_1902.getMessage());
        }
        LOG.info("tmp====" + JSONObject.toJSONString(tmp));
        LOG.info("aaaaaaa====" + (tmp.getPid() != daliMerchant.getId()));
        if (!tmp.getPid().equals(daliMerchant.getId())) {
            throw new BusinessException(ExceptionEnum.ERROR_1902.getCode(), ExceptionEnum.ERROR_1902.getMessage());
        }
        DailiMerchant param = new DailiMerchant();
        param.setId(result.getId());
        param.setProportion(result.getProportion());
        param.setIsEnable(result.getIsEnable());
        dailiMerchantDao.updateById(param);
    }

    @Override
    public void updateQuota(DailiMerchantResult result) throws BusinessException {
        Merchant merchant = merchantDao.findById(result.getMerchantId());
        DailiMerchantQuery daliMerchantQuery = new DailiMerchantQuery();
        daliMerchantQuery.setMobile(merchant.getMobile());
        DailiMerchant daliMerchant = dailiMerchantDao.findFirst(daliMerchantQuery);
        if (daliMerchant == null) {
            throw BusinessException.build(ExceptionEnum.ERROR_1907);
        }
        if (!DailiMerchantRoleEnum.PARTNER.getCode().equals(daliMerchant.getRole())) {
            throw BusinessException.build(ExceptionEnum.ERROR_1908);
        }
        Double quota = dailiMerchantDao.findQuotaByPid(daliMerchant.getPidPath());
        DailiMerchant merchantDaili = dailiMerchantDao.findById(result.getId());
        Double dailiMerchantQuota = merchantDaili.getQuota();
        if (merchantDaili.getQuota() == null) {
            dailiMerchantQuota = 0.0;
        }
        LOG.info("quota===" + quota);
        LOG.info("daliMerchant.getQuota() - quota===" + (daliMerchant.getQuota() - quota));
        LOG.info("result.getQuota()===" + result.getQuota());
        if (result.getQuota() > daliMerchant.getQuota() - quota + dailiMerchantQuota) {
            throw BusinessException.build(ExceptionEnum.ERROR_1909);
        }
        DailiMerchant param = new DailiMerchant();
        param.setId(result.getId());
        param.setQuota(result.getQuota());
        dailiMerchantDao.updateById(param);
    }

    @Override
    public void examine(DailiMerchantResult result) throws BusinessException {
        DailiMerchant item = new DailiMerchant();
        BeanUtilExt.copyProperties(item, result);
        DailiMerchant tmp = dailiMerchantDao.findById(item.getId());
        if (tmp == null) {
            throw new BusinessException(ExceptionEnum.ERROR_0002.getCode(), ExceptionEnum.ERROR_0002.getMessage());
        }
        if (!DailiMerchantStatusEnum.WAIT.getCode().equals(tmp.getStatus())) {
            throw new BusinessException(ExceptionEnum.ERROR_1901.getCode(), ExceptionEnum.ERROR_1901.getMessage());
        }
        if (DailiMerchantStatusEnum.REFUSE.getCode().equals(tmp.getStatus())) {
            if (StringUtils.isNotEmpty(tmp.getExplain())) {
                throw new BusinessException(ExceptionEnum.ERROR_1906.getCode(), ExceptionEnum.ERROR_1906.getMessage());
            }
        }
        dailiMerchantDao.updateById(item);
    }

    @Override
    public void add(InsertMerchantReq result) throws BusinessException {
        DailiMerchantQuery param = new DailiMerchantQuery();
        param.setMobile(result.getMobile());
        DailiMerchant merchantDaoFirst = dailiMerchantDao.findFirst(param);
        ValidateBusinessException.assertNull(merchantDaoFirst, ExceptionEnum.ERROR_1900);
        DailiMerchant item = new DailiMerchant();
        BeanUtilExt.copyProperties(item, result);
        item.setMobile(result.getMobile());
        item.setCreateTime(new Date());
        item.setStatus(DailiMerchantStatusEnum.SUCCESS.getCode());
        item.setRole(DailiMerchantRoleEnum.PARTNER.getCode());
        item.setPid(0);
        dailiMerchantDao.insert(item);
        DailiMerchant update = new DailiMerchant();
        update.setId(item.getId());
        update.setPidPath(item.getId() + ",");
        dailiMerchantDao.updateById(update);
        if (result.getSkuIds() != null && result.getSkuIds().size() > 0) {
            List<DailiMerchantSku> list = new ArrayList<>();
            for (Integer skuId : result.getSkuIds()) {
                DailiMerchantSku dailiMerchantSku = new DailiMerchantSku();
                dailiMerchantSku.setDailiMerchantId(item.getId());
                dailiMerchantSku.setDailiSkuId(skuId);
                dailiMerchantSku.setCreateTime(new Date());
                list.add(dailiMerchantSku);
            }
            dailiMerchantSkuDao.insertBatch(list);
        }
        if (result.getQuota() != null) {
            Platform platform = platformDao.findById(result.getPlatformId());
            DailiMerchantQuotaLog dailiMerchantQuotaLog = new DailiMerchantQuotaLog();
            dailiMerchantQuotaLog.setDailiMerchantId(item.getId());
            dailiMerchantQuotaLog.setType(IntegralOperationEnum.ADD.getCode());
            dailiMerchantQuotaLog.setQuota(result.getQuota());
            dailiMerchantQuotaLog.setName(platform.getName());
            dailiMerchantQuotaLog.setCreateTime(new Date());
            dailiMerchantQuotaLogDao.insert(dailiMerchantQuotaLog);
        }
    }

    @Override
    public void apply(InsertMerchantReq req) throws BusinessException {
        Merchant merchant = merchantDao.findById(req.getMerchantId());
        ValidateBusinessException.assertNonNull(merchant, ExceptionEnum.ERROR_1402);
        DailiMerchantQuery param = new DailiMerchantQuery();
        param.setMobile(merchant.getMobile());
        DailiMerchant merchantDaoFirst = dailiMerchantDao.findFirst(param);
        if (merchantDaoFirst != null && DailiMerchantRoleEnum.MERCHANT.getCode().equals(merchantDaoFirst.getRole())) {
            throw BusinessException.build(ExceptionEnum.ERROR_1900);
        }
        if (merchantDaoFirst == null) {
            DailiMerchant item = new DailiMerchant();
            BeanUtilExt.copyProperties(item, req);
            item.setMobile(merchant.getMobile());
            item.setCreateTime(new Date());
            item.setStatus(DailiMerchantStatusEnum.WAIT.getCode());
            item.setRole(DailiMerchantRoleEnum.PARTNER.getCode());
            item.setPid(0);
            dailiMerchantDao.insert(item);
            DailiMerchant update = new DailiMerchant();
            update.setId(item.getId());
            update.setPidPath(item.getId() + ",");
            dailiMerchantDao.updateById(update);
        } else {
            DailiMerchant update = new DailiMerchant();
            update.setId(merchantDaoFirst.getId());
            update.setPidPath(merchantDaoFirst.getId() + ",");
            update.setStatus(DailiMerchantStatusEnum.WAIT.getCode());
            update.setRole(DailiMerchantRoleEnum.PARTNER.getCode());
            update.setPid(0);
            dailiMerchantDao.updateById(update);
        }


    }

    @Override
    public Map<Integer, DailiMerchantResult> getItemMap(Set<Integer> idSet) {
        Map<Integer, DailiMerchantResult> map = new HashMap<Integer, DailiMerchantResult>();
        List<DailiMerchant> list = dailiMerchantDao.findByIds(StringUtil.setToList(idSet));
        List<DailiMerchantResult> resultList = DTOUtils.convertList(list, DailiMerchantResult.class);
        for (DailiMerchantResult item : resultList) {
            map.put(item.getId(), item);
        }

        return map;
    }

    @Override
    public Map<Integer, DailiMerchantResult> getItemMap() {
        Map<Integer, DailiMerchantResult> map = new HashMap<Integer, DailiMerchantResult>();
        DailiMerchantQuery param = new DailiMerchantQuery();
        List<DailiMerchant> list = dailiMerchantDao.page(param, 0, Integer.MAX_VALUE);
        List<DailiMerchantResult> resultList = DTOUtils.convertList(list, DailiMerchantResult.class);
        for (DailiMerchantResult item : resultList) {
            map.put(item.getId(), item);
        }
        return map;
    }

    @Override
    public Page<DailiMerchantResult> getListByMerchantId(Integer merchantId, String date, PagerInfo pr) {
        Page<DailiMerchantResult> page = new Page<>(pr.getPageIndex(), pr.getPageSize());
        Merchant merchant = merchantDao.findById(merchantId);
        DailiMerchantQuery daliMerchantQuery = new DailiMerchantQuery();
        daliMerchantQuery.setMobile(merchant.getMobile());
        DailiMerchant daliMerchant = dailiMerchantDao.findFirst(daliMerchantQuery);
        if (daliMerchant == null) {
            return page;
        }
        if (DailiMerchantRoleEnum.PARTNER.getCode().equals(daliMerchant.getRole())) {
            DailiMerchantQuery param = new DailiMerchantQuery();
            param.setPid(daliMerchant.getId());
            param.setRole(DailiMerchantRoleEnum.DISTRIBUTOR.getCode());
            Integer count = dailiMerchantDao.count(param);
            if (count > 0) {
                List<DailiMerchant> dailiMerchantList = dailiMerchantDao.page(param, pr.getStart(), pr.getPageSize());
                List<DailiMerchantResult> dailiMerchantResults = DTOUtils.convertList(dailiMerchantList, DailiMerchantResult.class);
                for (DailiMerchantResult dailiMerchantResult : dailiMerchantResults) {
                    DailiSupplierSubOrderResult dailiSupplierSubOrderResult = dailiOrderDao.getDailiSupplierSubOrderResult(date, null, null, dailiMerchantResult.getPidPath());
                    dailiMerchantResult.setOrderCount(dailiSupplierSubOrderResult.getCount());
                    dailiMerchantResult.setFengxiaoyuanAmount(dailiSupplierSubOrderResult.getFengxiaoyuanAmount());
                }
                page.setData(dailiMerchantResults);
            }
        }
        return page;
    }

    @Override
    public Page<DailiMerchantResult> getMerchantListByMerchantId(String mobile, Integer merchantId, PagerInfo pr) {
        Page<DailiMerchantResult> page = new Page<>(pr.getPageIndex(), pr.getPageSize());
        Merchant merchant = merchantDao.findById(merchantId);
        DailiMerchantQuery daliMerchantQuery = new DailiMerchantQuery();
        daliMerchantQuery.setMobile(merchant.getMobile());
        DailiMerchant daliMerchant = dailiMerchantDao.findFirst(daliMerchantQuery);
        if (daliMerchant == null) {
            return page;
        }
        DailiMerchantQuery param = new DailiMerchantQuery();
        param.setPidPath(daliMerchant.getPidPath());
        param.setRole(DailiMerchantRoleEnum.MERCHANT.getCode());
        param.setMobile(mobile);
        Integer count = dailiMerchantDao.count(param);
        page.setTotalPage(count);
        if (count > 0) {
            List<DailiMerchant> dailiMerchantList = dailiMerchantDao.page(param, pr.getStart(), pr.getPageSize());
            List<DailiMerchantResult> dailiMerchantResults = DTOUtils.convertList(dailiMerchantList, DailiMerchantResult.class);
            for (DailiMerchantResult dailiMerchantResult : dailiMerchantResults) {
                DailiMerchant pidDailiMerchant = dailiMerchantDao.findById(dailiMerchantResult.getPid());
                if (pidDailiMerchant != null) {
                    dailiMerchantResult.setBelong(pidDailiMerchant.getName());
                }
                if (dailiMerchantResult.getQuota() != null && dailiMerchantResult.getQuota() > 0) {
                    MerchantQuery merchantQuery = new MerchantQuery();
                    merchantQuery.setMobile(dailiMerchantResult.getMobile());
                    Merchant first = merchantDao.findFirst(merchantQuery);
                    if (first != null) {
                        Double enjoyPayPrice = skuOrderDao.getEnjoyPayPrice(first.getId(), null, null);
                        dailiMerchantResult.setSurplusQuota(dailiMerchantResult.getQuota() - enjoyPayPrice);
                    }
                }
            }
            page.setData(dailiMerchantResults);
        }

        return page;
    }

    @Override
    public Boolean dailiMerchantIsHaving(String mobile, String dailiMobile) throws BusinessException {
        DailiMerchantQuery dailiMerchantQ = new DailiMerchantQuery();
        dailiMerchantQ.setMobile(dailiMobile);
        DailiMerchant dailiMerchant = dailiMerchantDao.findFirst(dailiMerchantQ);

        DailiMerchantQuery dailiMerchantQuery = new DailiMerchantQuery();
        dailiMerchantQuery.setMobile(mobile);
        DailiMerchant merchant = dailiMerchantDao.findFirst(dailiMerchantQuery);
        if (merchant == null) {
            return true;
        } else {
            if (merchant.getPid() != dailiMerchant.getId()) {
                DailiMerchant dailiMerchantDaoById = dailiMerchantDao.findById(merchant.getPid());
                MerchantQuery merchantQuery = new MerchantQuery();
                merchantQuery.setMobile(dailiMerchantDaoById.getMobile());
                Merchant first = merchantDao.findFirst(merchantQuery);

                String message = ExceptionEnum.ERROR_1910.getMessage();
                String xxx = message.replaceAll("xxx", first.getName());
                throw BusinessException.build(ExceptionEnum.ERROR_1910.getCode(), xxx);
            }
        }
        return true;
    }


}
